package com.jeff.tianti.cms.service;

import com.jeff.tianti.cms.dto.font.IJobQueryDTO;
import com.jeff.tianti.cms.dto.font.JobTo;
import com.jeff.tianti.cms.entity.Job;
import com.jeff.tianti.cms.dao.JobDao;
import com.jeff.tianti.cms.dto.JobQueryDTO;
import com.jeff.tianti.cms.entity.Resume;
import com.jeff.tianti.common.service.CommonService;
import com.jeff.tianti.common.entity.PageModel;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

/**
 * @author liuyi
 * @desc JobService类
 * @date 2019-06-28
 */
@Service
public class JobService extends CommonService<Job, String> {

    @Autowired
    private JobDao jobDao;

    @Autowired
    public void setJobDao(JobDao jobDao) {
        super.setCommonDao(jobDao);
    }

    public PageModel<Job> queryJobPage(JobQueryDTO jobQueryDTO) {
        return this.jobDao.queryJobPage(jobQueryDTO);
    }

    public List<Job> queryJobList(JobQueryDTO jobQueryDTO) {
        return this.jobDao.queryJobList(jobQueryDTO);
    }


    public Page<Job> findAllNoDel(IJobQueryDTO dto) {
        Pageable pageable = new PageRequest(dto.getCurrentPage(), dto.getPageSize());
        String publishType = dto.getPublishType();
        if (StringUtils.isEmpty(publishType)) {
            publishType = null;
        }
        String areaId = dto.getAreaId();
        if (StringUtils.isEmpty(areaId)) {
            areaId = null;
        }
        String jobType = dto.getJobType();
        if (StringUtils.isEmpty(jobType)) {
            jobType = null;
        }
        return jobDao.findAllNoDel(publishType, areaId, jobType, pageable);
    }

    public PageModel<Resume> queryJobPages(JobTo jobTo) {
        return jobDao.queryJobPages(jobTo);
    }

    public List<Job>  findByUidAndPage(String uid) {
        return jobDao.findByUidAndPage(uid);
    }
}